var newsTable;
function getNewsList(name) {
    if (typeof newsTable !== 'undefined') {
        newsTable.fnPageChange('first');
        return;
    }
    var i = 1;
    newsTable = $("#newsList").DataTable({
        "sAjaxSource": _path + "/mcadvice/queryByPage",
        "fnServerParams": function (aoData) {
            aoData.push(
                { "name": "status", "value": $("#status").val() },
                { "name": "fromDate", "value": $("#fromDate").val() },
                { "name": "toDate", "value": $("#toDate").val() },
                { "name": "keyType", "value": $("#keyType").val() },
                { "name": "keywords", "value": $("#keywords").val() }
            );
        },
        "sServerMethod": "POST",
        "sAjaxDataProp": "dataList",
        "fnCreatedRow": function () {
            i++;
        },
        "fnPreDrawCallback": function () {
            i = 1;
        },
        "aoColumns": [
            { "sTitle": "序号", "sWidth": "2%",
                "mData": function () {
                    return i;
                }
            },
         /*   { "sTitle": "标题", "sWidth": "10%" ,"mData": 
	            	function(data){
	        		var temps = '<a href="' + _path + '/advice/edit/' + data.id + '"  target="_blank">'+data.title+'</a>';
	        		return temps;
	        	}
	        },*/
            { "sTitle": "视频编号", "mData": "title", "sWidth": "10%" },
            { "sTitle": "播放地址", "mData": "author", "sWidth": "30%" },
         //   { "sTitle": "单位", "mData": "username", "sWidth": "10%" },
//            { "sTitle": "状态", "mData": "status", "sWidth": "10%",
//                "mRender": function (data) {
//                    var status = '';
//                    switch (data) {
//                        case '0':
//                            status = '未查看';
//                            break;
//                        case '1':
//                            status = '查看录用';
//                            break;
//                        default :
//                            status = '查看未录用';
//                            break;
//                    }
//                    return status;
//                }
//            },
            { "sTitle": "发布时间", "mData": "falseCreateTime", "sWidth": "10%" },
            { "sTitle": "操作", "sWidth": "10%",
                "mData": function (data) {
               // 		var status = '<a href="' + _path + '/advice/edit/' + data.id + '"  target="_blank" class="btn default btn-xs purple"><i class="fa fa-edit" title="编辑"></i></a>';
                //        status += '&nbsp;<a href="javascript:check('+ data.id+ ');"  class="btn default btn-xs red"><i class="fa fa-trash-o" title="删除"></i></a>';
                	var status = '<a    class="btn default btn-xs purple"><i class="fa fa-edit" onclick="check(this)"  id="'+data.id+'"  uname="'+data.username+'" title="编辑"></i></a>';
                    status += '&nbsp;<a    class="btn default btn-xs red"><i class="fa fa-camera" onclick="oke(this)"  id="'+data.id+'"  uname="'+data.username+'" title="查看视频"></i></a>';
                	return status;
                }
            }
        ]
    });
}

function oke(em){
	var name =document.getElementById("username").value;
	var uname=$(em).attr('uname');
	var id=$(em).attr('id');
	
/*	if (name=="admin") {
		layer.alert(id);
		layer.confirm('您确定要删除吗？', function(){
			location.href = _path + "/advice/play/" + id;
		}, function(){
		
		});
	} else {
		layer.alert('对不起你没有权限');
	} */
	location.href = _path + "/mcadvice/play/" + id;
}

function check(em){
	var name =document.getElementById("username").value;
	var uname=$(em).attr('uname');
	var id=$(em).attr('id');
	
	if (name=="admin" || name=='admin') {
			//window.open( _path + "/advice/edit/" + id,target="_blank");
		location.href = _path + "/mcadvice/edit/" + id;
	} else {
		layer.alert('对不起你没有权限');
	}

}